import axios from 'axios';

const ALBUM_URL = '/album/list';



const initialState = {
  id: '',
  thumbnailUrl: '',
  title: '',
  summary: '',
  list: [],
  introduction: '',
  author: {
    name: '',
    avatar: '',
  },
};

const albumModel = {
  namespace: 'album',
  state: initialState,
  effects: {
    *fetchAlbum({ payload }, { call, put }) {
      const { data } = yield call(axios.get, ALBUM_URL);
      yield put({
        type: 'setState',
        payload: data,
      });
    },
  },
  reducers: {
    setState(state = initialState, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};

export default albumModel;
